package com.chenlei.toppopup.util;

import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;

/**
 * Created by chenlei on 2017/12/13.
 */

public class DrawableUtils
{
  /**
   * @param drawableNormal  默认
   * @param drawableSelect  选中
   * @return StateListDrawable
   */
  public static StateListDrawable getSelectorDrawable(Drawable drawableNormal, Drawable drawableSelect)
  {
    StateListDrawable drawable = new StateListDrawable();
    //选中
    drawable.addState(new int[]{android.R.attr.state_selected}, drawableSelect);
    //未选中
    drawable.addState(new int[]{-android.R.attr.state_selected}, drawableNormal);
    return drawable;
  }

  /**
   * @param normal  默认颜色
   * @param checked 选种颜色
   * @return ColorStateList
   */
  public static ColorStateList getSelectorColor(int normal, int checked)
  {
    int[] colors = new int[]{normal, checked, normal};
    int[][] states = new int[3][];
    states[0] = new int[]{-android.R.attr.state_selected};
    states[1] = new int[]{android.R.attr.state_selected};
    states[2] = new int[]{};
    return new ColorStateList(states, colors);
  }
}
